package com.wtf.controller;

import com.wtf.service.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author tengfei wang
 * @version 1.0
 * @date Created in 2020/11/2
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/register/{email}/{password}/{code}")
    public boolean register(@PathVariable("email") String email,
                            @PathVariable("password") String password,
                            @PathVariable("code") Integer code,
                            HttpServletResponse response) {
        return userService.register(email, password, code, response);
    }

    @RequestMapping("/isRegistered/{email}")
    public boolean isRegister(@PathVariable("email") String email) {
        return userService.isRegister(email);
    }

    @RequestMapping("/login/{email}/{password}")
    public String login(@PathVariable("email") String email,
                        @PathVariable("password") String password,
                        HttpServletResponse response) {
        return userService.login(email, password, response);
    }

    @RequestMapping("/info/{token}")
    public String getEmailByToken(@PathVariable("token") String token) {
        return userService.getEmailByToken(token);
    }
}
